//
//  ListVC.m
//  诗词鉴赏
//
//  Created by Steven on 2019/7/23.
//  Copyright © 2019 Steven. All rights reserved.
//

#import "ListVC.h"
#import "ListCell.h"

#import "ShiciListVC.h"
#import "DDBBaseItem.h"
@interface ListVC ()

@end

@implementation ListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.data[@"title"];
    self.tableView.tableFooterView = [UIView new];
    DDBBaseItem *item = [[DDBBaseItem alloc]init];
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.data[@"contents"] count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSDictionary *data = self.data[@"contents"][indexPath.row];
    ListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListCell" forIndexPath:indexPath];
    cell.header.image = [UIImage imageNamed:data[@"title"]];
    cell.titleLabel.text = data[@"title"];
    
    NSMutableArray *array = [NSMutableArray array];
    for (Shici *model in appData.shiciDatas) {
        for (NSString *titleStr in model.tagArr) {
            if ([titleStr isEqualToString:data[@"title"]]) {
                [array addObject:model];
            }
        }
    }
    cell.countLabel.text = [NSString stringWithFormat:@"(%lu)",(unsigned long)array.count];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *data = self.data[@"contents"][indexPath.row];
    
    
    NSMutableArray *array = [NSMutableArray array];
    for (Shici *model in appData.shiciDatas) {
        for (NSString *titleStr in model.tagArr) {
            if ([titleStr isEqualToString:data[@"title"]]) {
                [array addObject:model];
            }
        }
    }

    ShiciListVC *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"ShiciListVC"];
    vc.title = self.title;
    vc.dataArray = array;
    [self.navigationController pushViewController:vc animated:YES];

}

@end
